package com.yupi.yuaiagent.demo.invoke;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONArray;

public class CurlAiInvoke {
    public static void main(String[] args) {
        // 替换为你的 API Key
        String apiKey = TestApiKey.API_KEY;

        // 构建请求体
        JSONObject body = new JSONObject();
        body.put("model", "qwen-plus");

        // 构建 input
        JSONObject input = new JSONObject();
        JSONArray messages = new JSONArray();

        JSONObject systemMsg = new JSONObject();
        systemMsg.put("role", "system");
        systemMsg.put("content", "You are a helpful assistant.");

        JSONObject userMsg = new JSONObject();
        userMsg.put("role", "user");
        userMsg.put("content", "你是谁？");

        messages.add(systemMsg);
        messages.add(userMsg);

        input.put("messages", messages);
        body.put("input", input);

        // 构建 parameters
        JSONObject parameters = new JSONObject();
        parameters.put("result_format", "message");
        body.put("parameters", parameters);

        // 发送 POST 请求
        HttpResponse response = HttpRequest.post("https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation")
                .header("Authorization", "Bearer " + apiKey)
                .header("Content-Type", "application/json")
                .body(body.toString())
                .execute();

        // 输出响应内容
        System.out.println(response.body());
    }
}